/*
 * newContactoEmpresaForm.java
 *
 * Created on 4/09/2011, 10:27:53 AM
 */
package GUI;

import Classes.Empresa;
import Classes.GoogleMap;
import Persistencia.CiudadesMapper;
import PureFactoryClasses.ApController;
import javax.swing.JOptionPane;

/**
 *
 * @author Juampi
 */
public class newContactoEmpresaForm extends javax.swing.JDialog {

    private boolean contactExist;
    private Empresa empresa = new Empresa();
    private AgendaView agendaView;
    private boolean isEditing;

    public newContactoEmpresaForm(AgendaView agendaView, boolean modal) {
        super(agendaView.getFrame(), modal);
        this.agendaView = agendaView;
        initComponents();
        setEditable(true);
        this.setSize(330, 250);
        contactExist = false;
        isEditing = false;
        lblMap.setVisible(false);
    }

    public newContactoEmpresaForm(AgendaView agendaView, boolean modal, Empresa empresa) {
        super(agendaView.getFrame(), modal);
        this.agendaView = agendaView;
        initComponents();
        this.setSize(751, 280);
        setEditable(false);
        lblMap.setVisible(true);

        this.setResizable(false);
        try {
            this.empresa = empresa;
            this.txtCP.setText(String.valueOf(empresa.getCiudad().getCodigoPostal()));
            this.txtDir.setText(String.valueOf(empresa.getDireccion()));
            this.txtMail.setText(empresa.getCorreoElectronico());
            this.txtRazonSocial.setText(empresa.getRazonSocial());
            this.txtRubros.setText(empresa.getRubros());
            this.txtTelefono.setText(String.valueOf(empresa.getTelefono()));
            this.txtURL.setText(empresa.getUrlWeb());
            contactExist = true;
            this.btnAccept.setText("Aceptar");
            this.jLabel1.setText(empresa.getRazonSocial());
            this.lblMap.setIcon(GoogleMap.getInstance().getImagenMapa(empresa.getDireccion() + " " + empresa.getCiudad().getLocalidad(), lblMap.getWidth(), lblMap.getHeight()));
        } catch (Exception ex) {
        }
    }

    private void setEditable(boolean editable) {
        txtCP.setEnabled(editable);
        txtDir.setEnabled(editable);
        txtMail.setEnabled(editable);
        txtRazonSocial.setEnabled(editable);
        txtRubros.setEnabled(editable);
        txtTelefono.setEnabled(editable);
        txtURL.setEnabled(editable);
        btnEdit.setVisible(!editable);
        btnDelete.setVisible(contactExist);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        panelContenedorPrincipal = new javax.swing.JPanel();
        panelCabecera = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        panelBotonera = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        btnDelete = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        btnAccept = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        panelCentral = new javax.swing.JPanel();
        panelAtributos = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtRazonSocial = new javax.swing.JTextField();
        jPanel10 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtRubros = new javax.swing.JTextField();
        jPanel11 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        txtMail = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtURL = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtDir = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtCP = new javax.swing.JTextField();
        panelMapa = new javax.swing.JPanel();
        lblMap = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(GUI.AgendaApp.class).getContext().getResourceMap(newContactoEmpresaForm.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setMinimumSize(new java.awt.Dimension(480, 280));
        setName("Form"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        panelContenedorPrincipal.setMinimumSize(new java.awt.Dimension(500, 232));
        panelContenedorPrincipal.setName("panelContenedorPrincipal"); // NOI18N
        panelContenedorPrincipal.setPreferredSize(new java.awt.Dimension(500, 232));
        panelContenedorPrincipal.setLayout(new java.awt.BorderLayout());

        panelCabecera.setName("panelCabecera"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        panelCabecera.add(jLabel1);

        panelContenedorPrincipal.add(panelCabecera, java.awt.BorderLayout.PAGE_START);

        panelBotonera.setName("panelBotonera"); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        btnDelete.setText(resourceMap.getString("btnDelete.text")); // NOI18N
        btnDelete.setMaximumSize(new java.awt.Dimension(75, 23));
        btnDelete.setMinimumSize(new java.awt.Dimension(75, 23));
        btnDelete.setName("btnDelete"); // NOI18N
        btnDelete.setPreferredSize(new java.awt.Dimension(75, 23));
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnEdit.setText(resourceMap.getString("btnEdit.text")); // NOI18N
        btnEdit.setName("btnEdit"); // NOI18N
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(btnEdit))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnDelete, btnEdit});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(btnEdit)
                    .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnDelete, btnEdit});

        jPanel2.setName("jPanel2"); // NOI18N

        btnAccept.setText(resourceMap.getString("btnAccept.text")); // NOI18N
        btnAccept.setMaximumSize(new java.awt.Dimension(64, 28));
        btnAccept.setMinimumSize(new java.awt.Dimension(64, 28));
        btnAccept.setName("btnAccept"); // NOI18N
        btnAccept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAcceptActionPerformed(evt);
            }
        });
        jPanel2.add(btnAccept);

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);

        javax.swing.GroupLayout panelBotoneraLayout = new javax.swing.GroupLayout(panelBotonera);
        panelBotonera.setLayout(panelBotoneraLayout);
        panelBotoneraLayout.setHorizontalGroup(
            panelBotoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoneraLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(79, 79, 79)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(302, 302, 302))
        );
        panelBotoneraLayout.setVerticalGroup(
            panelBotoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoneraLayout.createSequentialGroup()
                .addGroup(panelBotoneraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelContenedorPrincipal.add(panelBotonera, java.awt.BorderLayout.PAGE_END);

        panelCentral.setName("panelCentral"); // NOI18N

        panelAtributos.setName("panelAtributos"); // NOI18N
        panelAtributos.setLayout(new java.awt.GridBagLayout());

        jPanel8.setName("jPanel8"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jPanel8.add(jLabel2);

        txtRazonSocial.setText(resourceMap.getString("txtRazonSocial.text")); // NOI18N
        txtRazonSocial.setMinimumSize(new java.awt.Dimension(130, 26));
        txtRazonSocial.setName("txtRazonSocial"); // NOI18N
        txtRazonSocial.setPreferredSize(new java.awt.Dimension(130, 26));
        jPanel8.add(txtRazonSocial);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel8, gridBagConstraints);

        jPanel10.setName("jPanel10"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        jPanel10.add(jLabel6);

        txtTelefono.setMinimumSize(new java.awt.Dimension(130, 26));
        txtTelefono.setName("txtTelefono"); // NOI18N
        txtTelefono.setPreferredSize(new java.awt.Dimension(130, 26));
        jPanel10.add(txtTelefono);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel10, gridBagConstraints);

        jPanel9.setName("jPanel9"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        jPanel9.add(jLabel4);

        txtRubros.setMinimumSize(new java.awt.Dimension(130, 26));
        txtRubros.setName("txtRubros"); // NOI18N
        txtRubros.setPreferredSize(new java.awt.Dimension(130, 26));
        jPanel9.add(txtRubros);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel9, gridBagConstraints);

        jPanel11.setName("jPanel11"); // NOI18N
        jPanel11.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        jPanel11.add(jLabel8);

        txtMail.setMinimumSize(new java.awt.Dimension(130, 26));
        txtMail.setName("txtEMail"); // NOI18N
        txtMail.setPreferredSize(new java.awt.Dimension(130, 26));
        jPanel11.add(txtMail);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel11, gridBagConstraints);

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jPanel1.add(jLabel3);

        txtURL.setMinimumSize(new java.awt.Dimension(130, 26));
        txtURL.setName("txtURL"); // NOI18N
        txtURL.setPreferredSize(new java.awt.Dimension(130, 26));
        txtURL.setRequestFocusEnabled(false);
        jPanel1.add(txtURL);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.ipadx = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel1, gridBagConstraints);

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.X_AXIS));

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        jPanel4.add(jLabel5);

        txtDir.setText(resourceMap.getString("txtDir.text")); // NOI18N
        txtDir.setMinimumSize(new java.awt.Dimension(180, 26));
        txtDir.setName("txtDir"); // NOI18N
        txtDir.setPreferredSize(new java.awt.Dimension(180, 26));
        txtDir.setRequestFocusEnabled(false);
        jPanel4.add(txtDir);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 4, 3, 4);
        panelAtributos.add(jPanel4, gridBagConstraints);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        jPanel3.add(jLabel7);

        txtCP.setMinimumSize(new java.awt.Dimension(130, 26));
        txtCP.setName("txtCP"); // NOI18N
        txtCP.setPreferredSize(new java.awt.Dimension(130, 26));
        txtCP.setRequestFocusEnabled(false);
        jPanel3.add(txtCP);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.BASELINE_TRAILING;
        gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
        panelAtributos.add(jPanel3, gridBagConstraints);

        panelMapa.setName("panelMapa"); // NOI18N

        lblMap.setText(resourceMap.getString("lblMap.text")); // NOI18N
        lblMap.setName("lblMap"); // NOI18N

        javax.swing.GroupLayout panelMapaLayout = new javax.swing.GroupLayout(panelMapa);
        panelMapa.setLayout(panelMapaLayout);
        panelMapaLayout.setHorizontalGroup(
            panelMapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMapaLayout.createSequentialGroup()
                .addComponent(lblMap, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelMapaLayout.setVerticalGroup(
            panelMapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMapaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblMap, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout panelCentralLayout = new javax.swing.GroupLayout(panelCentral);
        panelCentral.setLayout(panelCentralLayout);
        panelCentralLayout.setHorizontalGroup(
            panelCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCentralLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelAtributos, javax.swing.GroupLayout.PREFERRED_SIZE, 448, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelMapa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        panelCentralLayout.setVerticalGroup(
            panelCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCentralLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelMapa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panelAtributos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelContenedorPrincipal.add(panelCentral, java.awt.BorderLayout.CENTER);

        getContentPane().add(panelContenedorPrincipal);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAcceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAcceptActionPerformed
        if (validarDatos()) {
            ApController apController = ApController.getInstance();
            empresa.setCiudad(CiudadesMapper.getInstance().getCiudad(Integer.valueOf(txtCP.getText())));
            empresa.setCorreoElectronico(txtMail.getText());
            empresa.setDireccion(txtDir.getText());
            empresa.setRazonSocial(txtRazonSocial.getText());
            empresa.setRubros(txtRubros.getText());
            empresa.setTelefono(Integer.valueOf(txtTelefono.getText()));
            empresa.setUrlWeb(txtURL.getText());
            if (!contactExist) {
                if (!apController.agregarEmpresa(empresa)) {
                    JOptionPane.showMessageDialog(null, "Error de conexion con la Base de datos");
                }
                agendaView.loadContactTable();
            } else {
                if (isEditing) {
                    if (!apController.modificarEmpresa(empresa)) {
                        JOptionPane.showMessageDialog(null, "Error de conexion con la Base de datos");
                    }
                    agendaView.loadContactTable();
                }
            }

            this.dispose();
        }
    }//GEN-LAST:event_btnAcceptActionPerformed
    private boolean validarDatos() {
        if ((this.txtRazonSocial.getText() == null) || (this.txtRazonSocial.getText().equals(""))) {
            JOptionPane.showMessageDialog(null, "La razon social no esta completa.");
            return false;
        }
        if (!this.txtCP.getText().matches("[0-9]+")) {
            JOptionPane.showMessageDialog(null, "El codigo postal esta incompleto.");
            return false;
        }

        if ((this.txtDir.getText() == null) || (this.txtDir.getText().equals(""))) {
            JOptionPane.showMessageDialog(null, "La direccion debe estar completa");
            return false;
        }
        if ((!this.txtMail.getText().matches("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"))) {
            JOptionPane.showMessageDialog(null, "El mail no es valido.");
            return false;
        }

        if (!this.txtTelefono.getText().matches("[0-9]{4,10}")) {
            JOptionPane.showMessageDialog(null, "El telefono no es correcto.");
            return false;
        }
        if ((this.txtRubros.getText() == null) || (this.txtRubros.getText().equals(""))) {
            JOptionPane.showMessageDialog(null, "Debe completar los rubros.");
            return false;
        }
        if (!this.txtURL.getText().matches("www.*.*")) {
            JOptionPane.showMessageDialog(null, "La URL no es correcta.");
            return false;
        }
        return true;


    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        if ((JOptionPane.showConfirmDialog(this, "¿Confirma que desea eliminar el contacto?") == JOptionPane.OK_OPTION)) {
            if (!ApController.getInstance().borrarContacto(empresa)) {
                JOptionPane.showMessageDialog(null, "Error de conexion a la base de datos");
            } else {
                agendaView.loadContactTable();
                this.dispose();
            }
        }
}//GEN-LAST:event_btnDeleteActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        setEditable(true);
        isEditing = true;
    }//GEN-LAST:event_btnEditActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAccept;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JLabel lblMap;
    private javax.swing.JPanel panelAtributos;
    private javax.swing.JPanel panelBotonera;
    private javax.swing.JPanel panelCabecera;
    private javax.swing.JPanel panelCentral;
    private javax.swing.JPanel panelContenedorPrincipal;
    private javax.swing.JPanel panelMapa;
    private javax.swing.JTextField txtCP;
    private javax.swing.JTextField txtDir;
    private javax.swing.JTextField txtMail;
    private javax.swing.JTextField txtRazonSocial;
    private javax.swing.JTextField txtRubros;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtURL;
    // End of variables declaration//GEN-END:variables
}
